<template>
<div id="comm">
<!-- 
<van-dialog
v-model="show"
:closeOnClickOverlay=true
:before-close="beforeClose"
:lockScroll=false
>
<van-field
v-model="content"
label="内容"
placeholder="请输入内容"
/>

</van-dialog> -->
<!-- 
     <Input v-model="content" v-if="show" placeholder="请输入内容" size="large" clearable style="width: 90%" enter-button="取消"/> -->

      <Input v-model="content"  v-if="show" placeholder="请输入内容"  style="width: 90%;"  :autofocus="true" on-enter="beforeClose()">
       
        <Button slot="append" icon="ios-search" @click="beforeClose"></Button>
    </Input>


</div>

</template>

<script>
import axios from 'axios'
import { Toast } from 'vant';
 import event from '@/pages/Commons/event.js'
export default {
data() {
return {
content:'',
event:1
};
},
props:{
show:false,
id:'',
userid:'',

},

methods: {
beforeClose(action) {
var token =localStorage.getItem('token');
var content=this.content;
var id =this.id;
var userid =this.userid;
if(content == ''){
Toast('请填写内容')
return;
}else{
axios.post('/api/publish/comment',{
id:id,
content:content,
replayer_id:userid
},{
headers: { 'Authorization': 'Bearer ' + token}
}).then(response=>{
console.log(response)
if(response.data.status==0){
Toast('评论成功')
this.content=''
this.show=false
 event.$emit('event', this.event)
 event.$emit('show', this.show)

}else{
Toast('评论失败')
this.show=false
}
})
}
},

yes(){



}
},
mounted(){

	event.$on('shows',(data)=>{
		console.log(data)
		if(data=false){
			this.content =""
		}
	})
}
}
</script>

<style>
/* .van-dialog{position: absolute;top: 10rem;left: 50%} */
</style>

